package com.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


public class sqlSessionUtiles {
    private static SqlSessionFactory sessionFactory;
    //加载核心配置文件
    static {
        try {
            InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
            sessionFactory = new SqlSessionFactoryBuilder().build(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /*
    创建sqlsession对象
     */
    public static SqlSession getSqlSession(){
        return sessionFactory.openSession();
    }
}
